<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增医疗机构管理')" />
    <th:block th:include="include :: datetimepicker-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-medical-add">
            <div class="form-group">
                <label class="col-sm-3 control-label">机构编号：</label>
                <div class="col-sm-8">
                    <input name="medicalId" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">机构名称：</label>
                <div class="col-sm-8">
                    <input id="medicalName" name="medicalName" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">区域区域编号：</label>
                <div class="col-sm-8">
                    <div class="input-group">
                        <input id="treeId" name="areaId" type="hidden" th:value="${sysArea?.areaId}"/>
                        <input class="form-control" type="text" onclick="selectAreaTree()" id="treeName" readonly="true" th:value="${sysArea?.areaName}">
                        <span class="input-group-addon"><i class="fa fa-search"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">主办单位：</label>
                <div class="col-sm-8">
                    <input name="host" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">成立时间：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <input name="startTime" class="form-control" placeholder="yyyy-MM-dd" type="text">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">负责人：</label>
                <div class="col-sm-8">
                    <input name="director" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">注册资金：</label>
                <div class="col-sm-8">
                    <input name="capital" class="form-control" type="text">
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <script th:inline="javascript">
        var prefix = ctx + "system/medical"
        $("#form-medical-add").validate({
            focusCleanup: true
        });

        function submitHandler() {
            let medicalName = $("#medicalName").val();
            $.ajax ({
                url: '/system/medical/listAjax',
                type: 'post',
                dataType: 'json',
                data: {"medicalName": medicalName},
                success: function(data) {
                    if (data.res == 'success') {
                        if ($.validate.form()) {
                            $.operate.save(prefix + "/add", $('#form-medical-add').serialize());
                        }
                    } else {
                        $.modal.msgError("医疗机构名称重复！");
                    }
                }
            });
        }

        $("input[name='startTime']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        /*行政区域管理-新增-选择行政区域树*/
        function selectAreaTree() {
            var options = {
                title: '行政区域管理选择',
                width: "380",
                url: "/system/area/selectAreaTree/" + $("#treeId").val(),
                callBack: doSubmit
            };
            $.modal.openOptions(options);
        }

        /*行政区域树的回调函数*/
        function doSubmit(index, layero){
            var body = layer.getChildFrame('body', index);
            $("#treeId").val(body.find('#treeId').val());
            $("#treeName").val(body.find('#treeId').val());
            $("#areaId").val(body.find('#treeId').val());
            layer.close(index);
        }
    </script>
</body>
</html>
